' 
' Copyright (C) 2014 Infinity CCS Ltd (http://www.infinityccs.com/)
' Copyright (C) 2007 Sasa Coh <sasacoh@gmail.com>
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program.  If not, see <http://www.gnu.org/licenses/>. 
'/


Imports Infinity.pjsipNET.Common
Imports Infinity.pjsipNET.Common.CallState

Namespace CallControl.CallState

#Region "Terminated"
  ''' <summary>
  ''' Released State indicates call has been released by user and waiting for destruction.
  ''' The state machine will be destroyed on onReleased event from stack or on released timer 
  ''' timeout
  ''' </summary>
  Friend Class Terminated
    Inherits IState

    Public Sub New(sm As CallMachine)
      MyBase.New(sm)
      Id = EStateId.TERMINATED
    End Sub

    ''' <summary>
    ''' Enter release state. If release timer not implemented release call imediately
    ''' </summary>
    Friend Overrides Sub OnEntry()
      Dim success As Boolean = _smref.StartTimer(Timer.ETimerType.ERELEASED, 5) '5 seconds
      If Not success Then _smref.Destroy()
    End Sub

    Friend Overrides Sub OnExit()
      _smref.StopAllTimers()
    End Sub

    Public Overrides Function endCall() As Boolean
      CallProxy.endCall()
      Return True
    End Function

    Public Overrides Function releasedTimerExpired(sessionId As Integer) As Boolean
      _smref.Destroy()
      Return True
    End Function

    Public Overrides Sub onAlerting()
      CallProxy.endCall()
    End Sub

    Public Overrides Sub onConnect()
      CallProxy.endCall()
    End Sub

    ''' <summary>
    ''' Destroy state machine 
    ''' </summary>
    Public Overrides Sub onReleased()
      _smref.Destroy()
    End Sub
  End Class
#End Region

End Namespace
